unit Form_Client;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, rtcDataCli, rtcInfo, rtcConn, rtcHttpCli, StdCtrls;

type
  TForm1 = class(TForm)
    HttpClient1: TRtcHttpClient;
    DataRequest1: TRtcDataRequest;
    Btnx_Connect: TButton;
    Btnx_Send: TButton;
    procedure Btnx_ConnectClick(Sender: TObject);
    procedure DataRequest1BeginRequest(Sender: TRtcConnection);
    procedure Btnx_SendClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Btnx_ConnectClick(Sender: TObject);
begin
  HttpClient1.ServerAddr:='localhost';
  HttpClient1.ServerPort:='8080';
  HttpClient1.Connect();
end;

procedure TForm1.Btnx_SendClick(Sender: TObject);
begin
  DataRequest1.Request.Method:='POST'; // Use the "HTTP POST" method
  DataRequest1.Request.FileName:='/FORMPARAM?password=test'; // Set the "FileName" to receive the request
  DataRequest1.Request.Host:=HttpClient1.ServerAddr; // Set the "Host" HTTP header
  DataRequest1.Post(); // Post the request to the request queue
end;

procedure TForm1.DataRequest1BeginRequest(Sender: TRtcConnection);
var
  DataClient:TRtcDataClient absolute Sender;
begin
  DataClient.Request.ContentType:='application/x-www-form-urlencoded'; // important!!!
  // Set all POST variables (in our case, "username" and "pwd")
  DataClient.Request.Params.Value['params-username']:=URL_Encode('result-params-username');
  DataClient.Request.Params.Value['params-password']:=URL_Encode('result-params-password');
  DataClient.Request.Query.Value['query-username']  :=URL_Encode('result-query-username');
  DataClient.Request.Query.Value['query-password']  :=URL_Encode('result-query-password');
  // Use the "Write" method to send "Params.Text" ("FORM-URLENCODED" values) to the Server
  //ShowMessage(DataClient.Request.Params.Text);
  DataClient.Write(DataClient.Request.Params.Text);
end;

end.
